package Demo16_30.Test29;

import java.io.*;
import java.net.Socket;

/**
 * Created by 14229 on 2020/1/31.
 */
public class Client {
    public static void main(String[] args) throws IOException {

        Socket socket = new Socket("192.168.1.42", 12345);

        //获取输出流
        OutputStream os = socket.getOutputStream();

        //创建字节输入流  用来读取原数据
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("qwqw.jpg"));

        byte[] bys = new byte[1024];
        int len = -1 ;
        while ((len = bis.read(bys))!=-1){
            os.write(bys,0,len);
        }

        socket.shutdownOutput();

        //响应服务器信息
        InputStream is = socket.getInputStream();
        byte[] bytes = new byte[1024];
        int lenth = is.read(bytes);

        System.out.println(new String(bytes,0,lenth));


        is.close();
        bis.close();
        os.close();

        socket.close();

    }
}
